package com.mt.baseinfo.service.impl;

import com.mt.baseinfo.request.GetTokenRequest;
import com.mt.baseinfo.service.AuthService;
import com.mt.baseinfo.service.RegistHandleService;
import com.mt.baseinfo.until.JwtUtil;
import com.mt.common.dto.ResponseResult;
import io.jsonwebtoken.Claims;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;

/**
 * @date 2018/08/15
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class RegistHandleServiceImpl implements RegistHandleService {

    @Autowired
    private AuthService authService;

    /**
     * 登录
     * @param getTokenRequest 对象
     * @return ResponseResult实例
     */
    @Override
    public ResponseResult handle(GetTokenRequest getTokenRequest) {
       return new ResponseResult();
    }

    /**
     * 登出
     * @param request token
     * @return ResponseResult 实例
     */
    @Override
    public ResponseResult checkOut(GetTokenRequest request){
        String strToken = request.getToken();
        Claims claims = JwtUtil.parseJWT(strToken);
        String subject = claims.getSubject();
        authService.deleteToken(subject);
        return ResponseResult.success("");
    }
}
